package homework;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class Test03 {
    public static void main1(String[] args) {
        //3.分别使用文件流和缓冲流复制一个长度大于100MB的视频文件，并观察效率的差异。
        long start = System.currentTimeMillis();
        try (FileInputStream fis = new FileInputStream("D:\\course\\02-JavaSE进阶\\day11-多线程\\录屏\\117-文件夹拷贝案例.avi");
             FileOutputStream fos = new FileOutputStream("day10-code/src/homework/1.avi"))
            {
            byte[] car = new byte[1024];
            int len;
            while ((len = fis.read(car)) != -1) {
                fos.write(car,0,len);
                fos.flush();
            }
        }catch (Exception e) {
            e.printStackTrace();
        }

        System.out.println("复制完毕");
        long end = System.currentTimeMillis();
        System.out.println("耗时：" + (end - start) + "毫秒");//耗时：1474毫秒

    }

    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        try (BufferedInputStream fis = new BufferedInputStream(new FileInputStream("D:\\course\\02-JavaSE进阶\\day11-多线程\\录屏\\117-文件夹拷贝案例.avi"));
             BufferedOutputStream fos = new BufferedOutputStream(new FileOutputStream("day10-code/src/homework/1.avi")))
        {
            byte[] car = new byte[1024];
            while (fis.read(car) != -1) {
                fos.write(car);
            }
        }catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("复制完毕");
        long end = System.currentTimeMillis();
        System.out.println("耗时：" + (end - start) + "毫秒");//耗时：295毫秒

    }
}
